home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JAVA_UTL / HYPERPRO / SRC / PVS / UTILS / BORDERPA.JAV next >
Encoding:
Text File  |  1996-09-14  |  1.4 KB  |  66 lines

  1. package PVS.Utils;
  2.  
  3. import java.awt.*;
  4.  
  5. public class BorderPanel extends Panel
  6. {
  7.   int border = 2;    // size of border
  8.   Color col1,col2,cback;
  9.  
  10.   public static final int RECESSED = 0, RAISED = 1; // PRESSED, DEPRESSED
  11.  
  12.   public int state = RECESSED;
  13.   public static int insets_ = 1;
  14.  
  15.   public BorderPanel() {
  16.     this(RECESSED);
  17.   }
  18.  
  19.   public BorderPanel(int state) {
  20.     this.state = state;
  21.     cback = new Color(192,192,192);
  22.     if(state == RECESSED){
  23.       col1 = cback.darker();
  24.       col2 = cback.brighter();
  25.     } else {
  26.       col2 = cback.darker();
  27.       col1 = cback.brighter();
  28.     }
  29.   }
  30.   
  31.   public BorderPanel(int w, Color c1, Color c2) {    
  32.     border = w;
  33.     col1 = c1; col2 = c2;
  34.   }
  35.   
  36.   public BorderPanel(Color c1, Color c2) {
  37.     col1 = c1; col2 = c2;
  38.   }
  39.   
  40.   public Insets insets() {
  41.     return new Insets(border+insets_, border+insets_, border+insets_, border+insets_);
  42.   }
  43.  
  44.   public void update(Graphics g){
  45.     paint(g);
  46.   }
  47.  
  48.   public void paint(Graphics g) {
  49.     super.paint(g);
  50.     Dimension d = size();
  51.     int w = d.width-1, h = d.height-1;
  52.     g.setColor(cback);
  53.     g.fillRect(0,0,d.width,d.height);
  54.     g.setColor(col1);
  55.     for(int i=0; i<border; i++) {
  56.       g.drawLine(i,i,w-i,i);
  57.       g.drawLine(i,i,i,h-i);
  58.     }
  59.     g.setColor(col2);
  60.     for(int i=0; i<border; i++) {
  61.       g.drawLine(w-i,h-i, w-i,i);
  62.       g.drawLine(w-i,h-i, i,h-i);
  63.     }
  64.   }
  65. }
  66.